package com.pinc.exam;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class Summary_Adapter extends MyBaseAdapter<Summary_Class> {
	private int mode;
	public static final int MODE_NORMAL = 0;
	public static final int MODE_ANSWER = 1;
	private String[] SEL_CHAR;

	public Summary_Adapter(Context context) {
		super(context);
		items = new ArrayList<Summary_Class>();
		mode = MODE_NORMAL;
		SEL_CHAR = context.getResources().getStringArray(R.array.selChar);
	}

	public void setAnswer(int pos, int answer)
	{
		items.get(pos).user_answer = answer;
	}

	public void setMode(int mode)
	{
		this.mode = mode;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = inflater.inflate(R.layout.summary_item, null);

		TextView tv_a = (TextView) view.findViewById(R.id.textView_Answer);
		TextView tv_u = (TextView) view.findViewById(R.id.textView_uAnswer);
		TextView tv_h = (TextView) view.findViewById(R.id.textView_header);
		TextView tv_q = (TextView) view.findViewById(R.id.textView_question);

		if ( mode == MODE_NORMAL)
		{
			tv_a.setVisibility(View.GONE);
		}
		else
		{
			if ( items.get(position).user_answer >0 && items.get(position).real_answer[items.get(position).user_answer-1])
			{
				tv_a.setText("");
			}
			else
			{
				//				tv_a.setText(SEL_CHAR[items.get(position).real_answer]);
				tv_a.setText("X");
				view.setBackgroundResource(R.drawable.summary_wrong_bg);
			}

		}

		tv_u.setText(SEL_CHAR[items.get(position).user_answer]);
		tv_h.setText(String.format("%d.", position+1));
		tv_q.setText(items.get(position).question);

		return view;
	}

}
